home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 211_01 / scoper.c < prev    next >
Text File  |  1980-01-01  |  10KB  |  420 lines

  1. /* SCOPER.C    VERS:- 01.00  DATE:- 09/26/86  TIME:- 09:36:45 PM */
  2. /*
  3. %CC1 $1.C 
  4. */
  5. /* 
  6. Description:
  7.  
  8. Library of functions for full screen input.
  9.  
  10. Minor modification of SCOPE, from CUG distribution disk:
  11.     changed some control character representations;
  12.     added tabs;
  13.     clear and unprotect screen at entry, before set NOROLL and
  14.         display template in <crtbuf>.
  15.  
  16. By J.A. Rupley, Tucson, Arizona
  17. Coded for BDS C compiler, version 1.50a
  18. */
  19.  
  20. /*The SCOPE function is a full screen processor designed for a terminal with
  21. a 24 x 80 capability. It currently runs on a SOROK 120 or 140 but can be 
  22. adapted to run on other terminals such as TELEVIDEO and/or also changed to 
  23. allow for different control characters. The general purpose of SCOPE is
  24. twofold. It has one mode where it will allow n screenfulls of data to be 
  25. manipulated (n is controlled by parameter size) and this data may be 
  26. modified in typical full screen editor format. A delete and insert character,
  27. delete and insert line, pick and put a line, and goto first or last page
  28. capability is provided. Also an erase back one character is provided. The
  29. up and down arrows as well as the carriage return may be used to control
  30. scrolling. (up scrolling is nice but unfortunately down scrolling is not)
  31. The left and right arrows will rotate on a single line.  There is built in 
  32. error checks to prevent the arrows from going off either the beginning or
  33. end of the data.  Also notice that there are no nulls on the scope, blanks
  34. are used so that the arrows may be positioned at will without affecting the 
  35. display. To return to the calling function you must do one of three special
  36. sequences (RETURN1,RETURN2,RETURN3). Which sequence is chosen is returned to
  37. the calling function. Option is set to zero.
  38.    A second option of SCOPE is a read-only mode so that SCOPE may be used to
  39. display lists from which a choice is to be made.  In this mode only the curser
  40. control keys are active and any other key will be ignored. The SCOPE program 
  41. returns the character position to which the curser is last set so that the 
  42. procedure is merely to set the curser to the line of interest and return to
  43. the calling program. Option is set to non-zero.
  44.    The other two parameters are crtbuf, an array large enough to hold all
  45. of the characters of interest. e.g. if a 2-screenful system is applied then
  46. array should be at least 3840 characters and size should be set to 3840.
  47.    Notice that SCOPE is completely controlled by function 6 of CPM or MPM.
  48. (It has different code for each OS) and therefore any character is legal.
  49. An abort is recognized but it merely returns a -1 to the calling function
  50. and must be dealt with there.
  51. */
  52.  
  53.     /* page eject */
  54.  
  55. #define LOAD bdos(6,'\033');bdos(6,'=');
  56. #define NOROLL bdos(6,'\033');bdos(6,'&');
  57. #define ROLL bdos(6,'\033');bdos(6,'\047');
  58. #define CLRSCOPE bdos(6,'\033');bdos(6,'*');
  59. #define BLANK 32
  60. #define HOME 30            /*CTRL-^*/
  61. #define UP 11            /*four arrow keys*/
  62. #define DOWN 10             
  63. #define FORWARD 12        
  64. #define BACK 8            
  65. #define CR 13 
  66. #define TAB 9            /*CTRL-I*/
  67. #define FIRST 'R' - 0x40
  68. #define LAST 'C' - 0x40
  69. #define OPEN 'N' - 0x40
  70. #define CLOSE 'Y' - 0x40
  71. #define PICK 'Q' - 0x40
  72. #define PUT 'W' -0x40
  73. #define INSERT 'V' - 0x40
  74. #define GOBBLE 'G' - 0x40
  75. #define RUB 127            /*DEL*/
  76. #define ABORT 'Z' -0x40
  77. #define OUT 0x1b        /*ESC*/    
  78. #define OUT1 0x1b        /*ESC*/
  79. #define OUT2 'U' - 0x40
  80. #define OUT3 0x1b        /*ESC*/
  81.  
  82. scope(crtbuf, curser, size, opt)
  83. char crtbuf[];
  84. int curser;
  85. int size;
  86. int opt;
  87. {
  88.     char b;
  89.     int c;
  90.     int first;
  91.     int insert;
  92.     char stack[21];
  93.     char pickbuf[80];
  94.  
  95.     stack[20] = call(5, 0, 0, 12, 0) > 255;
  96.     CLRSCOPE
  97.         NOROLL
  98.         insert = first = 0;
  99.     setmem(pickbuf, 80, ' ');
  100.     stack[0] = stack[1] = 2;
  101.     outbuf(crtbuf, first, curser);
  102.     /*OUT = ESC*/
  103.     while ((b = getbyte(stack)) != OUT)
  104.     {
  105.         /*OUT1 = control X, OUT2 = control U, OUT3 = ESC*/
  106.         if (b == OUT1 || b == OUT2 || b == OUT3)
  107.             break;
  108.         inbyte(stack);
  109.         switch (b)
  110.         {
  111.         case 0 :        /*nothing typed*/
  112.             continue;
  113.         case LAST :        /*last page (control C)*/
  114.             fix(crtbuf, curser, insert);
  115.             first = curser = size - 1920;
  116.             outbuf(crtbuf, first, curser);
  117.             break;
  118.         case ABORT :        /*control Z (abort)*/
  119.             CLRSCOPE
  120.                 return (-1);
  121.         case PUT :        /*put (control W)*/
  122.             if (opt)
  123.                 continue;
  124.             c = open1(crtbuf, curser, size);
  125.             movmem(pickbuf, &crtbuf[c], 80);
  126.             outbuf(crtbuf, first, curser);
  127.             break;
  128.         case PICK :        /*pick (control Q)*/
  129.             if (opt)
  130.                 continue;
  131.             c = (curser / 80) * 80;
  132.             movmem(&crtbuf[c], pickbuf, 80);
  133.             continue;
  134.         case BACK :        /*left arrow*/
  135.             fix(crtbuf, curser, insert);
  136.             if ((curser % 80) == 0)
  137.             {
  138.                 curser += 79;
  139.                 setcurs(curser, first);
  140.                 break;
  141.             }
  142.             curser--;
  143.             bdos(6, b);
  144.             break;
  145.         case GOBBLE :        /*gobble (control G)*/
  146.             if (opt)
  147.                 continue;
  148.             c = 79 - (curser % 80);
  149.             movmem(&crtbuf[curser + 1], &crtbuf[curser], c);
  150.             crtbuf[curser + c] = ' ';
  151.             liner(crtbuf, curser, c + 1, first, stack);
  152.             setcurs(curser, first);
  153.             break;
  154.         case TAB :        /*tab (control I)*/
  155.             fix(crtbuf, curser, insert);
  156.             curser += (8 - (((curser % 80) % 8)));
  157.             if ((curser % 80) < 8)
  158.                 curser -= 80;
  159.             setcurs(curser, first);
  160.             break;
  161.         case FORWARD :        /*right arrow*/
  162.             fix(crtbuf, curser, insert);
  163.             if ((++curser % 80) == 0)
  164.             {
  165.                 curser -= 80;
  166.                 setcurs(curser, first);
  167.                 break;
  168.             }
  169.             bdos(6, b);
  170.             break;
  171.         case UP :        /*up arrow*/
  172.             fix(crtbuf, curser, insert);
  173.             if ((curser -= 80) < 0)
  174.             {
  175.                 curser += 80;
  176.                 continue;
  177.             }
  178.             if (curser < first)
  179.             {
  180.                 first -= 80;
  181.                 outbuf(crtbuf, first, curser);
  182.                 break;
  183.             }
  184.             bdos(6, b);
  185.             break;
  186.         case DOWN :        /*down arrow*/
  187.             fix(crtbuf, curser, insert);
  188.             curser += 80;
  189.             if (curser >= size)
  190.             {
  191.                 curser -= 80;
  192.                 continue;
  193.             }
  194.             if (curser >= (first + 1920))
  195.             {
  196.                 first += 80;
  197.                 outline(crtbuf, first + 1840, 80, first);
  198.                 setcurs(curser, first);
  199.                 break;
  200.             }
  201.             bdos(6, b);
  202.             break;
  203.         case CR :        /*carriage return*/
  204.             if (opt)
  205.                 return (curser);
  206.             fix(crtbuf, curser, insert);
  207.             c = curser % 80;
  208.             curser = curser + 80 - c;
  209.             if (curser >= size)
  210.             {
  211.                 curser = curser - 80 + c;
  212.                 continue;
  213.             }
  214.             if (curser >= (first + 1920))
  215.             {
  216.                 first += 80;
  217.                 outline(crtbuf, first + 1840, 80, first);
  218.                 setcurs(curser, first);
  219.                 break;
  220.             }
  221.             bdos(6, b);
  222.             bdos(6, DOWN);
  223.             break;
  224.         case FIRST :        /*first page (control R)*/
  225.             fix(crtbuf, curser, insert);
  226.             first = curser = 0;
  227.             outbuf(crtbuf, first, curser);
  228.             break;
  229.         case CLOSE :        /*close (control Y)*/
  230.             if (opt)
  231.                 continue;
  232.             fix(crtbuf, curser, insert);
  233.             c = (curser / 80) * 80;
  234.             movmem(&crtbuf[c + 80], &crtbuf[c], size - c);
  235.             setmem(&crtbuf[size - 80], 80, ' ');
  236.             outbuf(crtbuf, first, curser);
  237.             break;
  238.         case OPEN :        /*open (control N)*/
  239.             if (opt)
  240.                 continue;
  241.             open1(crtbuf, curser, size);
  242.             outbuf(crtbuf, first, curser);
  243.             break;
  244.         case INSERT :        /*insert (control V)*/
  245.             if (opt)
  246.                 continue;
  247.             if ((++insert & 1) == 0)
  248.             {
  249.                 bdos(6, crtbuf[curser]);
  250.                 bdos(6, BACK);
  251.             }
  252.             break;
  253.         case HOME :        /*home (control ^)*/
  254.             fix(crtbuf, curser, insert);
  255.             curser = first;
  256.             setcurs(0, 0);
  257.             break;
  258.         case RUB :        /*rub (delete key)*/
  259.             if (opt)
  260.                 continue;
  261.             if ((curser % 80) == 0)
  262.                 continue;
  263.             fix(crtbuf, curser, insert);
  264.             bdos(6, BACK);
  265.             bdos(6, BLANK);
  266.             bdos(6, BACK);
  267.             crtbuf[--curser] = ' ';
  268.             break;
  269.         default :
  270.             /*printing characters */
  271.             if (opt || b < 32 || b > 126)
  272.                 continue;
  273.             if (insert & 1)
  274.             {
  275.                 if ((c = curser % 80) == 79)
  276.                     continue;
  277.                 movmem(&crtbuf[curser], &crtbuf[curser + 1], 79 - c);
  278.                 crtbuf[curser] = b;
  279.                 bdos(6, b);
  280.                 liner(crtbuf, ++curser, 79 - c, first, stack);
  281.                 setcurs(curser, first);
  282.                 break;
  283.             }
  284.             if (++curser >= (first + 1920))
  285.             {
  286.                 crtbuf[--curser - 1] = b;
  287.                 bdos(6, b);
  288.                 setcurs(c